package szc.common.code.file;

import szc.common.code.enums.FileTypeEnum;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;

import java.io.File;
import java.util.Collection;

/**
 * @desc java文件
 * @author songzc
 * @date 2022/6/18
 */
public class CodeFileFinder {
	private File rootFileDirectory;
	private IOFileFilter codeFilter;

	public CodeFileFinder(File rootDirectory, FileTypeEnum fileTypeEnum) {
		this.rootFileDirectory = rootDirectory;
		this.codeFilter = FileFilterUtils.suffixFileFilter(fileTypeEnum.getSuffix());
	}

	public Collection<File> findAllFiles() {
		return FileUtils.listFiles(this.rootFileDirectory, this.codeFilter, TrueFileFilter.INSTANCE);
	}
}